#include "coupler.h"
#include "adapter_api.h"

int Adapter_SendTextMsg(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_SendTextMsg(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->toWxid, pApiParameterStruct->msg);
}

int Adapter_SendTextMsgByByteHex(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_SendTextMsgByByteHex(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->toWxid, pApiParameterStruct->byteHex);
}

int Adapter_SendGroupMsgAndAt(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_SendGroupMsgAndAt(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->groupWxid, pApiParameterStruct->memberWxid, pApiParameterStruct->memberName,
                                 pApiParameterStruct->msg);
}

int Adapter_SendCardMsg(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_SendCardMsg(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->toWxid, pApiParameterStruct->cardData);
}

int Adapter_SendImageMsg(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_SendImageMsg(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->toWxid, pApiParameterStruct->path);
}

int Adapter_SendFileMsg(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_SendFileMsg(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->toWxid, pApiParameterStruct->path);
}

int Adapter_SendEmojiMsg(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_SendEmojiMsg(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->toWxid, pApiParameterStruct->path);
}

int Adapter_SendVideoMsg(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_SendVideoMsg(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->toWxid, pApiParameterStruct->path);
}

int Adapter_SendLinkMsg(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_SendLinkMsg(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->toWxid, pApiParameterStruct->title, pApiParameterStruct->text,
                           pApiParameterStruct->targetUrl, pApiParameterStruct->picUrl, pApiParameterStruct->iconUrl);
}

int Adapter_SendMusicMsg(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_SendMusicMsg(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->toWxid, pApiParameterStruct->name, pApiParameterStruct->type);
}

LPCSTR Adapter_GetRobotName(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_GetRobotName(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid);
}

LPCSTR Adapter_GetRobotHeadimgurl(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_GetRobotHeadimgurl(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid);
}

LPCSTR Adapter_GetLoggedAccountList(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_GetLoggedAccountList(pApiParameterStruct->authCode);
}

LPCSTR Adapter_GetFriendList(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_GetFriendList(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->isRefresh);
}

LPCSTR Adapter_GetGroupList(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_GetGroupList(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->isRefresh);
}

LPCSTR Adapter_GetGroupMemberList(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_GetGroupMemberList(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->groupWxid, pApiParameterStruct->isRefresh);
}

LPCSTR Adapter_GetGroupMemberDetailInfo(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_GetGroupMemberDetailInfo(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->groupWxid, pApiParameterStruct->memberWxid, pApiParameterStruct->isRefresh);
}

int Adapter_ReloadPlug(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_ReloadPlug(pApiParameterStruct->authCode);
}

int Adapter_DeleteFriend(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_DeleteFriend(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->friendWxid);
}

int Adapter_ModifyFriendNote(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_ModifyFriendNote(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->friendWxid, pApiParameterStruct->note);
}

int Adapter_BuildingGroup(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_BuildingGroup(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->friends);
}

int Adapter_ModifyGroupName(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_ModifyGroupName(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->groupWxid, pApiParameterStruct->groupName);
}

int Adapter_ModifyGroupNotice(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_ModifyGroupNotice(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->groupWxid, pApiParameterStruct->content);
}

int Adapter_QuitGroup(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_QuitGroup(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->groupWxid);
}

int Adapter_RemoveGroupMember(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_RemoveGroupMember(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->groupWxid, pApiParameterStruct->memberWxid);
}

int Adapter_InviteInGroup(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_InviteInGroup(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->groupWxid, pApiParameterStruct->friendWxid);
}

int Adapter_AcceptTransfer(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_AcceptTransfer(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->fromWxid, pApiParameterStruct->jsonMsg);
}

int Adapter_AgreeFriendVerify(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_AgreeFriendVerify(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->jsonMsg);
}

int Adapter_AgreeGroupInvite(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_AgreeGroupInvite(pApiParameterStruct->authCode, pApiParameterStruct->robotWxid, pApiParameterStruct->jsonMsg);
}

LPCSTR Adapter_GetAppDirectory(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_GetAppDirectory(pApiParameterStruct->authCode);
}

int Adapter_AppendLogs(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_AppendLogs(pApiParameterStruct->authCode, pApiParameterStruct->msg);
}

int Adapter_SetFatal(PAdapter_ApiParameterStruct pApiParameterStruct) {
    return Api_SetFatal(pApiParameterStruct->authCode);
}

Adapter_ApiFuncAndNameStruct gApiFuncAndNameArray[] = {{"SendTextMsg", (Adapter_ApiFunc) Adapter_SendTextMsg},
                                                       {"SendTextMsgByByteHex", (Adapter_ApiFunc) Adapter_SendTextMsgByByteHex},
                                                       {"SendGroupMsgAndAt", (Adapter_ApiFunc) Adapter_SendGroupMsgAndAt},
                                                       {"SendCardMsg", (Adapter_ApiFunc) Adapter_SendCardMsg},
                                                       {"SendImageMsg", (Adapter_ApiFunc) Adapter_SendImageMsg},
                                                       {"SendFileMsg", (Adapter_ApiFunc) Adapter_SendFileMsg},
                                                       {"SendEmojiMsg", (Adapter_ApiFunc) Adapter_SendEmojiMsg},
                                                       {"SendVideoMsg", (Adapter_ApiFunc) Adapter_SendVideoMsg},
                                                       {"SendLinkMsg", (Adapter_ApiFunc) Adapter_SendLinkMsg},
                                                       {"SendMusicMsg", (Adapter_ApiFunc) Adapter_SendMusicMsg},
                                                       {"GetRobotName", (Adapter_ApiFunc) Adapter_GetRobotName},
                                                       {"GetRobotHeadimgurl", (Adapter_ApiFunc) Adapter_GetRobotHeadimgurl},
                                                       {"GetLoggedAccountList", (Adapter_ApiFunc) Adapter_GetLoggedAccountList},
                                                       {"GetFriendList", (Adapter_ApiFunc) Adapter_GetFriendList},
                                                       {"GetGroupList", (Adapter_ApiFunc) Adapter_GetGroupList},
                                                       {"GetGroupMemberList", (Adapter_ApiFunc) Adapter_GetGroupMemberList},
                                                       {"GetGroupMemberDetailInfo", (Adapter_ApiFunc) Adapter_GetGroupMemberDetailInfo},
                                                       {"ReloadPlug", (Adapter_ApiFunc) Adapter_ReloadPlug},
                                                       {"DeleteFriend", (Adapter_ApiFunc) Adapter_DeleteFriend},
                                                       {"ModifyFriendNote", (Adapter_ApiFunc) Adapter_ModifyFriendNote},
                                                       {"BuildingGroup", (Adapter_ApiFunc) Adapter_BuildingGroup},
                                                       {"ModifyGroupName", (Adapter_ApiFunc) Adapter_ModifyGroupName},
                                                       {"ModifyGroupNotice", (Adapter_ApiFunc) Adapter_ModifyGroupNotice},
                                                       {"QuitGroup", (Adapter_ApiFunc) Adapter_QuitGroup},
                                                       {"RemoveGroupMember", (Adapter_ApiFunc) Adapter_RemoveGroupMember},
                                                       {"InviteInGroup", (Adapter_ApiFunc) Adapter_InviteInGroup},
                                                       {"AcceptTransfer", (Adapter_ApiFunc) Adapter_AcceptTransfer},
                                                       {"AgreeFriendVerify", (Adapter_ApiFunc) Adapter_AgreeFriendVerify},
                                                       {"AgreeGroupInvite", (Adapter_ApiFunc) Adapter_AgreeGroupInvite},
                                                       {"GetAppDirectory", (Adapter_ApiFunc) Adapter_GetAppDirectory},
                                                       {"AppendLogs", (Adapter_ApiFunc) Adapter_AppendLogs},
                                                       {"SetFatal", (Adapter_ApiFunc) Adapter_SetFatal}};

DWORD32 Adapter_CallApi(LPCSTR apiName, PAdapter_ApiParameterStruct pApiParameterStruct) {
    for (UINT i = 0; i < sizeof(gApiFuncAndNameArray) / sizeof(Adapter_ApiFuncAndNameStruct); i++) {
        if (!lstrcmpiA(apiName, gApiFuncAndNameArray[i].apiName)) {
            return (DWORD32) gApiFuncAndNameArray[i].apiFunc(pApiParameterStruct);
        }
    }
    return 0xFFFFFFFF;
}

int Adapter_Initialize(int session, LPCSTR jsonStr) {
    return Api_Initialize(session, jsonStr);
}
